<!-- 到期设备 -->
<template>
  <div class="app-container">
    <div class="Filters">
      设备到期:
      <el-select v-model="filters.expireStatus" placeholder="Select" @change="getExpirePage" style="width: 120px"
        class="mrg-lf-10">
        <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
      </el-select>
      <el-segmented class="mrg-lf-10" v-model="segmented" :options="options2" @change="getExpirePage" />
      <!-- <el-date-picker class="mrg-lf-10" v-model="value1" type="date" placeholder="请选择日期" /> -->
      <el-button type="primary" class="mrg-lf-10">续期</el-button>
      <el-button type="primary" class="mrg-lf-10">赋值ID</el-button>
      <el-button type="primary" class="mrg-lf-10">导出Excel</el-button>
    </div>
    <el-table v-loading="loading" :data="pageData" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="50" align="center" />
      <el-table-column label="设备名称" align="center" prop="deviceName" />

      <el-table-column label="设备编号" align="center" prop="deviceCode" />
      <el-table-column label="客户名称" align="center" prop="customerName" />

      <el-table-column label="到期时间" align="center" prop="expireCondition" />

      <el-table-column label="上次离线时间" align="center" prop="lastOfflineTime" />
      <el-table-column label="模块名称" align="center" prop="modelName" />
      <el-table-column label="离线时长" align="center" prop="offlineCondition" />

      <!-- <el-table-column label="创建时间" align="center" prop="createTime" width="180" /> -->
      <!-- <el-table-column label="操作" fixed="right" width="220">
        <template #default="scope"></template>
</el-table-column> -->
    </el-table>
    <pagination @pagination="getExpirePage" v-if="filters.pages.total > 0" v-model:total="filters.pages.total"
      v-model:page="filters.pages.current" v-model:limit="filters.pages.size" />
  </div>
</template>

<script setup lang="ts">
import type { TabsPaneContext } from "element-plus";
import DeviceManagementApi, { ExpirePage } from "@/api/deviceManagement"


const loading = ref(false);
const removeIds = ref([]);
const segmented = ref(7);
let pageData = reactive([]);
const options = [
  {
    value: "NOT_EXPIRED",
    label: "即将过期",
  },
  {
    value: "EXPIRED",
    label: "过期",
  }
];
const options2 = [
  {
    value: 0,
    label: "全部",
  },
  {
    value: 7,
    label: "7天",
  },
  {
    value: 30,
    label: "30天内",
  },
  {
    value: 60,
    label: "60天内",
  },
  {
    value: 90,
    label: "90天内",
  }
];
let filters = reactive<ExpirePage>({
  "pages": {
    "current": 1,
    "size": 10,
    "total": 0,
    "startTime": "",
    "endTime": "",
    "orders": [
      {
        "column": "",
        "asc": true
      }
    ]
  },
  expireStatus: "NOT_EXPIRED",
  expireTime: 7,
  unit: 'DAYS'
});
/**
@date: 2024-09-11 11:39:52
查询设备分页列表
*/
function getExpirePage() {
  loading.value = true;
  if (segmented.value === 0) {
    filters.expireTime = undefined
    filters.unit = undefined
  } else {
    filters.expireTime = segmented.value
    filters.unit = 'DAYS'
  }
  DeviceManagementApi.getExpirePage(filters)
    .then((data) => {
      console.log(data);
      pageData = data.records;
      filters.pages.total = data.total;
      filters.pages.current = data.current;
    })
    .finally(() => {
      loading.value = false;
    });
}
/** 行复选框选中记录选中ID集合 */
function handleSelectionChange(selection: any) {
  removeIds.value = selection.map((item: any) => item.id);
}
const handleClick = (tab: TabsPaneContext, event: Event) => {
  console.log(tab, event);
};
onMounted(() => {
  // handleQuery();
  getExpirePage()
});
</script>
<style lang="scss" scoped>
.mrg-lf-10 {
  margin-left: 10px;
}

.app-container {
  position: relative;

  .allTabContent {
    display: flex;
    align-items: center;
    position: absolute;
    top: 15px;
    right: 0;

    div {
      margin-left: 26px;
      font-weight: 700;

      span {
        margin-left: 8px;
      }
    }
  }
}

.Filters {
  margin-bottom: 10px;
  display: flex;
  align-items: center;

  .el-segmented {
    --el-segmented-item-selected-color: var(--el-text-color-primary);
    --el-segmented-item-selected-bg-color: #5cadff;
    --el-border-radius-base: 16px;
  }

  &>div {
    margin-right: 5px;
  }
}
</style>
